<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是STM32开发——LCD显示的基本实现的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV16-26-LCD-04-LCD显示实现">
<meta property="og:url" content="https://sumumm.github.io/post/91da98e9.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是STM32开发——LCD显示的基本实现的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520165852112.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520172732803.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520172347644.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520172426959.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520193526299.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520190749494.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520190833399.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520192619072.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520192825396.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520193711597.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520195047470.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521102921252.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521155552530.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521160414233.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521161239928.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521161323673.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521161945923.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521162918219.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521163223952.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521163832776.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521170257692.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521170405650.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230522072202116.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230523123321969.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230523130810838.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230523131019129.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230523220742912.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524220030511.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524133046886.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524133125714.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524133202987.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524215000828.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524215142332.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524215313557.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524215421446.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524215619493.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524220303842.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230523132641086.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230523132732416.png">
<meta property="article:published_time" content="2023-06-04T14:07:39.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.014Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="LV16-STM32开发">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520165852112.png">


<link rel="canonical" href="https://sumumm.github.io/post/91da98e9.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/91da98e9.html","path":"post/91da98e9.html","title":"LV16-26-LCD-04-LCD显示实现"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV16-26-LCD-04-LCD显示实现 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E7%A1%AC%E4%BB%B6%E8%AE%BE%E8%AE%A1"><span class="nav-text">一、硬件设计</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E6%AD%A3%E7%82%B9%E5%8E%9F%E5%AD%902-8%E5%AF%B8LCD%E6%A8%A1%E5%9D%97"><span class="nav-text">1. 正点原子2.8寸LCD模块</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E9%9F%A6%E4%B8%9C%E5%B1%B1LCD%E5%B1%8F%E6%A8%A1%E5%9D%97"><span class="nav-text">2. 韦东山LCD屏模块</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81STM32CubeMX%E9%85%8D%E7%BD%AE"><span class="nav-text">二、STM32CubeMX配置</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-FSMC%E9%85%8D%E7%BD%AE"><span class="nav-text">1. FSMC配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-LCD%E8%83%8C%E5%85%89%E5%BC%95%E8%84%9A%E9%85%8D%E7%BD%AE"><span class="nav-text">2. LCD背光引脚配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E6%97%B6%E9%92%9F%E6%A0%91%E9%85%8D%E7%BD%AE"><span class="nav-text">3. 时钟树配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-FSMC%E6%97%B6%E5%BA%8F%E5%8F%82%E6%95%B0%E9%85%8D%E7%BD%AE"><span class="nav-text">4. FSMC时序参数配置</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-ILI9341%E6%97%B6%E5%BA%8F%E5%8F%82%E6%95%B0%E5%9B%BE"><span class="nav-text">4.1 ILI9341时序参数图</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-%E5%8F%82%E6%95%B0%E7%9A%84%E7%A1%AE%E5%AE%9A"><span class="nav-text">4.2 参数的确定</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81LCD%E5%9F%BA%E6%9C%AC%E9%A9%B1%E5%8A%A8%E5%AE%9E%E7%8E%B0"><span class="nav-text">三、LCD基本驱动实现</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E7%9B%B8%E5%85%B3%E5%AE%9A%E4%B9%89"><span class="nav-text">1. 相关定义</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-D-C%E5%9C%B0%E5%9D%80%E7%A1%AE%E5%AE%9A"><span class="nav-text">1. D&#x2F;C地址确定</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-1-%E7%BB%93%E6%9E%84%E4%BD%93%E5%81%8F%E7%A7%BB%E6%96%B9%E5%BC%8F"><span class="nav-text">1.1 结构体偏移方式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#1-2-%E7%9B%B4%E6%8E%A5%E5%AE%9A%E4%B9%89"><span class="nav-text">1.2 直接定义</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-%E9%A2%9C%E8%89%B2%E5%AE%9A%E4%B9%89"><span class="nav-text">1.2 颜色定义</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-3-LCD%E5%8F%82%E6%95%B0%E7%BB%93%E6%9E%84%E4%BD%93"><span class="nav-text">1.3 LCD参数结构体</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-FSMC%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="nav-text">2. FSMC初始化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-GPIO%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="nav-text">3. GPIO初始化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E8%AF%BB%E5%86%99%E5%87%BD%E6%95%B0%E5%AE%9E%E7%8E%B0"><span class="nav-text">4. 读写函数实现</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-%E5%90%91ILI9341%E5%86%99%E5%85%A5%E5%91%BD%E4%BB%A4"><span class="nav-text">4.1 向ILI9341写入命令</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-%E5%90%91ILI9341%E5%86%99%E5%85%A5%E6%95%B0%E6%8D%AE"><span class="nav-text">4.2 向ILI9341写入数据</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-%E4%BB%8EILI9341%E8%AF%BB%E5%8F%96%E6%95%B0%E6%8D%AE"><span class="nav-text">4.3 从ILI9341读取数据</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-4-%E8%AF%BB%E5%8F%96ILI9341-ID"><span class="nav-text">4.4 读取ILI9341 ID</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-5-IO%E9%97%AE%E9%A2%98"><span class="nav-text">4.5 __IO问题</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81LCD%E5%AF%84%E5%AD%98%E5%99%A8%E9%85%8D%E7%BD%AE"><span class="nav-text">四、LCD寄存器配置</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%B1%8F%E5%B9%95%E5%BC%80%E7%AA%97"><span class="nav-text">1. 屏幕开窗</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-Column-Address-Set-2Ah"><span class="nav-text">1.1 Column Address Set (2Ah) </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-Page-Address-Set-2Bh"><span class="nav-text">1.2 Page Address Set (2Bh)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-3-%E5%BC%80%E7%AA%97%E5%87%BD%E6%95%B0%E5%AE%9E%E7%8E%B0"><span class="nav-text">1.3 开窗函数实现</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E8%AE%BE%E7%BD%AE%E5%83%8F%E7%B4%A0%E6%A0%BC%E5%BC%8F"><span class="nav-text">2. 设置像素格式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-COLMOD-Pixel-Format-Set-3Ah"><span class="nav-text">2.1 COLMOD: Pixel Format Set (3Ah)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E5%87%BD%E6%95%B0%E5%AE%9E%E7%8E%B0"><span class="nav-text">2.2 函数实现</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%8F%91%E9%80%81%E5%83%8F%E7%B4%A0%E6%95%B0%E6%8D%AE"><span class="nav-text">3. 发送像素数据  </span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-Memory-Write-2Ch"><span class="nav-text">3.1 Memory Write (2Ch)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E5%87%BD%E6%95%B0%E5%AE%9E%E7%8E%B0"><span class="nav-text">3.2 函数实现</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E7%94%B5%E6%BA%90%E6%A8%A1%E5%BC%8F"><span class="nav-text">4. 电源模式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-%E6%A8%A1%E5%BC%8F%E7%8A%B6%E6%80%81%E8%AF%BB%E5%8F%96"><span class="nav-text">4.1 模式状态读取</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-1-1-Read-Display-Power-Mode-0Ah"><span class="nav-text">4.1.1 Read Display Power Mode (0Ah) </span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-1-2-%E5%87%BD%E6%95%B0%E5%AE%9E%E7%8E%B0"><span class="nav-text">4.1.2 函数实现</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-1-3-%E6%95%88%E6%9E%9C%E6%B5%8B%E8%AF%95"><span class="nav-text">4.1.3 效果测试</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-Sleep-In-Out-Mode"><span class="nav-text">4.2 Sleep In&#x2F;Out Mode</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-Display-ON-OFF"><span class="nav-text">4.3 Display ON&#x2F;OFF</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-4-%E7%94%B5%E6%BA%90%E6%A8%A1%E5%BC%8F%E9%85%8D%E7%BD%AE"><span class="nav-text">4.4 电源模式配置</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E8%AE%BE%E7%BD%AE%E6%B6%B2%E6%99%B6%E7%9A%84%E6%89%AB%E6%8F%8F%E6%96%B9%E5%90%91"><span class="nav-text">5. 设置液晶的扫描方向  </span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#5-1-Memory-Access-Control-36h"><span class="nav-text">5.1 Memory Access Control (36h)</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#5-1-1-%E5%91%BD%E4%BB%A4%E6%A0%BC%E5%BC%8F"><span class="nav-text">5.1.1 命令格式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-1-2-MH-Horizontal-Refresh-ORDER"><span class="nav-text">5.1.2 MH(Horizontal Refresh ORDER)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-1-3-ML-Vertical-Refresh-Order"><span class="nav-text">5.1.3 ML(Vertical Refresh Order)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-1-4-MY%E3%80%81MX%E5%92%8CMV"><span class="nav-text">5.1.4 MY、MX和MV</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-2-Read-Display-MADCTL-0Bh"><span class="nav-text">5.2 Read Display MADCTL (0Bh) </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-3-%E6%B6%B2%E6%99%B6%E6%89%AB%E6%8F%8F%E6%96%B9%E5%90%91%E5%AE%9E%E7%8E%B0"><span class="nav-text">5.3 液晶扫描方向实现</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-ILI9341%E5%AF%84%E5%AD%98%E5%99%A8%E9%85%8D%E7%BD%AE"><span class="nav-text">6. ILI9341寄存器配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-%E5%BA%94%E7%94%A8%E5%87%BD%E6%95%B0"><span class="nav-text">7. 应用函数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#7-1-%E5%9F%BA%E7%A1%80%E5%87%BD%E6%95%B0"><span class="nav-text">7.1 基础函数</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#7-1-1-%E5%BC%80%E7%AA%97"><span class="nav-text">7.1.1 开窗</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-1-2-%E5%A1%AB%E5%85%85%E5%83%8F%E7%B4%A0%E7%94%BB%E5%9B%BE"><span class="nav-text">7.1.2 填充像素画图</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-1-3-%E6%B8%85%E5%B1%8F"><span class="nav-text">7.1.3 清屏</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-1-4-%E8%AE%BE%E7%BD%AE%E5%85%89%E6%A0%87%E4%BD%8D%E7%BD%AE"><span class="nav-text">7.1.4 设置光标位置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-1-5-%E7%94%BB%E4%B8%80%E4%B8%AA%E7%82%B9"><span class="nav-text">7.1.5 画一个点</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-2-%E4%B8%9A%E5%8A%A1%E5%87%BD%E6%95%B0"><span class="nav-text">7.2 业务函数</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#7-2-1-%E7%94%BB%E7%BA%BF"><span class="nav-text">7.2.1 画线</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-2-2-%E7%94%BB%E7%9F%A9%E5%BD%A2"><span class="nav-text">7.2.2 画矩形</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-2-3-%E7%94%BB%E5%9C%86"><span class="nav-text">7.2.3 画圆</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-2-4-%E8%AE%BE%E7%BD%AELCD%E8%83%8C%E6%99%AF%E9%A2%9C%E8%89%B2"><span class="nav-text">7.2.4 设置LCD背景颜色</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-2-5-%E8%AE%BE%E7%BD%AELCD%E7%94%BB%E7%AC%94%E9%A2%9C%E8%89%B2"><span class="nav-text">7.2.5 设置LCD画笔颜色</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-3-%E6%B5%8B%E8%AF%95%E5%87%BD%E6%95%B0"><span class="nav-text">7.3 测试函数</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-%E5%AE%8C%E6%95%B4%E5%8F%82%E8%80%83%E4%BB%A3%E7%A0%81"><span class="nav-text">8. 完整参考代码</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/91da98e9.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV16-26-LCD-04-LCD显示实现 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV16-26-LCD-04-LCD显示实现
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-06-04 22:07:39" itemprop="dateCreated datePublished" datetime="2023-06-04T22:07:39+08:00">2023-06-04</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/" itemprop="url" rel="index"><span itemprop="name">01HQ课程体系</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">LV16-STM32开发</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>13k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>46 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是STM32开发——LCD显示的基本实现的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">SecureCRT</td>        <td align="left">Version 8.7.2 (x64 build 2214)   -   正式版-2020年5月14日</td>      </tr>    <tr>        <td align="center">开发板</td>        <td align="left">正点原子 i.MX6ULL Linux阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03)</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.15(NXP官方提供)</td>      </tr>    <tr>        <td align="center">STM32开发板</td>        <td align="left">正点原子战舰V3(STM32F103ZET6)</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <ul><li>通用</li></ul><table><tr><td align="center">分类  </td><td align="center">网址</td><td align="center">说明</td></tr><tr><td align="center" rowspan="4">官方网站</td><td align="left"><a href="https://www.arm.com/" target="_blank">https://www.arm.com/</a></td><td align="left">ARM官方网站，在这里我们可以找到Cotex-Mx以及ARMVx的一些文档</td></tr><tr>                                            <td align="left"><a href="https://www.st.com/content/st_com/zh.html" target="_blank">https://www.st.com/content/st_com/zh.html</a></td><td align="left">ST官方网站，在这里我们可以找到STM32的相关文档</td></tr><tr>                                            <td align="left"><a href="https://www.stmcu.com.cn/" target="_blank">https://www.stmcu.com.cn/</a></td><td align="left">意法半导体ST中文官方网站，在这里我们可以找到STM32的相关中文参考文档</td></tr><tr>                                            <td align="left"><a href="http://elm-chan.org/fsw/ff/00index_e.html" target="_blank">http://elm-chan.org/fsw/ff/00index_e.html</a></td><td align="left">FatFs文件系统官网</td></tr><tr><td align="center" rowspan="3">教程书籍</td><td align="left"><a href="STM32开发相关资料/01ARM参考资料/ARM Cortex-M3权威指南(中文).pdf" target="_blank">《ARM Cortex-M3权威指南》</a></td><td alirn="left" rowspan="3">ARM公司专家Joseph Yiu（姚文祥）的力作，中文翻译是NXP的宋岩</td></tr><tr>                                            <td align="left"><a href="STM32开发相关资料/01ARM参考资料/ARM Cortex-M0权威指南(中文).pdf" target="_blank">《ARM Cortex-M0权威指南》</a></td></tr><tr>                                            <td align="left"><a href="" target="_blank">《ARM Cortex-M3与Cortex-M4权威指南》</a></td></tr><tr><td align="center" rowspan="4">开发论坛</td><td align="left"><a href="http://47.111.11.73/forum.php" target="_blank">http://47.111.11.73/forum.php</a></td><td align="left">开源电子网，正点原子的资料下载及问题讨论论坛</td></tr><tr>                                            <td align="left"><a href="https://www.firebbs.cn/forum.php" target="_blank">https://www.firebbs.cn/forum.php</a></td><td align="left">国内Kinetis开发板-野火/秉火（刘火良）主持的论坛，现也做STM32和i.MX RT</td></tr><tr>                                            <td align="left"><a href="https://www.amobbs.com/index.php" target="_blank">https://www.amobbs.com/index.php</a></td><td align="left">阿莫（莫进明）主持的论坛，号称国内最早最火的电子论坛，以交流Atmel AVR系列单片机起家，现已拓展到嵌入式全平台，其STM32系列帖子有70W+。</td></tr><tr>                                            <td align="left"><a href="http://download.100ask.net/index.html" target="_blank">http://download.100ask.net/index.html</a></td><td align="left">韦东山嵌入式资料中心，有些STM32和linux的相关资料也可以来这里找。</td></tr><tr><td align="center" rowspan="3">博客参考</td><td align="left"><a href="http://www.openedv.com/" target="_blank">http://www.openedv.com/</a></td><td align="left">开源网-原子哥个人博客</td></tr><tr>                                            <td align="left"><a href="http://blog.chinaaet.com/jihceng0622" target="_blank">http://blog.chinaaet.com/jihceng0622</a></td><td align="left">博主是原Freescale现NXP的现场应用工程师</td></tr><tr>                                            <td align="left"><a href="https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/cortex-m-resources" target="_blank">cortex-m-resources</a></td><td align="left">这其实并不算是一个博客，这是ARM公司专家Joseph Yiu收集整理的所有对开发者有用的官方Cortex-M资料链接（也包含极少数外部资源链接）</td></tr></table><ul><li>STM32</li></ul><table>    <tr><td align="center" rowspan="2">STM32</td><td align="left"><a href="https://doc.embedfire.com/mcu/stm32/f103/hal_general/zh/latest/index.html" target="_blank">STM32 HAL库开发实战指南——基于F103系列开发板</a></td><td align="left">野火STM32开发教程在线文档</td></tr><tr>                                            <td align="left"><a href="https://doc.embedfire.com/mcu/stm32/f103badao/std/zh/latest/index.html" target="_blank">STM32库开发实战指南——基于野火霸道开发板</a></td><td align="left">野火STM32开发教程在线文档</td></tr></table><ul><li>SD卡</li></ul><table>    <tr><td align="left"><a href="https://www.sdcard.org/" target="_blank">SD Association</a></td><td align="left">提供了SD存储卡和SDIO卡系统规范</td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr><td align="left"><a href="https://www.st.com/resource/en/datasheet/stm32f103ze.pdf" target="_blank">STM32F103xx英文数据手册</a></td><td align="left">STM32F103xC/D/E系列的英文数据手册</td></tr>    <tr><td align="left"><a href="https://www.stmcu.com.cn/Designresource/detail/localization_document%20/709978" target="_blank">STM32F103xx中文数据手册</a></td><td align="left">STM32F103xC/D/E系列的中文数据手册</td></tr>    <tr><td align="left"><a href="https://www.st.com/resource/en/reference_manual/rm0008-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf" target="_blank">STM32F10xxx英文参考手册（RM0008）</a></td><td align="left">STM32F10xxx系列的英文参考手册</td></tr>    <tr><td align="left"><a href="https://www.stmcu.com.cn/Designresource/detail/localization_document%20/710001" target="_blank">STM32F10xxx中文参考手册（RM0008）</a></td><td align="left">STM32F10xxx系列的中文参考手册</td></tr>    <tr><td align="left"><a href="https://developer.arm.com/documentation/100165/0201/?lang=en" target="_blank">Arm Cortex-M3 处理器技术参考手册-英文版</a></td><td align="left">Cortex-M3技术参考手册-英文版</td></tr>    <tr><td align="left"><a href="https://www.st.com/resource/en/programming_manual/pm0056-stm32f10xxx20xxx21xxxl1xxxx-cortexm3-programming-manual-stmicroelectronics.pdf" target="_blank">STM32F10xxx Cortex-M3编程手册-英文版(PM0056)</a></td><td align="left">STM32F10xxx/20xxx/21xxx/L1xxxx系列Cortex-M3编程手册-英文版</td></tr>    <tr><td align="left"><a href="https://www.sdcard.org/downloads/pls/" target="_blank">SD卡相关资料——最新版本</a></td><td align="left">有关SD卡的一些资料可以从这里下载</td></tr>    <tr><td align="left"><a href="https://www.sdcard.org/downloads/pls/archives/" target="_blank">SD卡相关资料——历史版本</a></td><td align="left">有关SD卡的一些历史版本资料可以从这里下载，比如后边看的SD卡2.0协议</td></tr>    <tr><td align="left"><a href="./" target="_blank">SD 2.0 协议标准完整版</a></td><td align="left">这是一篇关于SD卡2.0协议的中文文档，还是比较有参考价值的，可以一看</td></tr></table>
              </div>
            </details>

<p>这一节的笔记主要是LCD显示相关，不关注触摸屏相关引脚。</p>
<h1 id="一、硬件设计"><a href="#一、硬件设计" class="headerlink" title="一、硬件设计"></a><font size=3>一、硬件设计</font></h1><h2 id="1-正点原子2-8寸LCD模块"><a href="#1-正点原子2-8寸LCD模块" class="headerlink" title="1. 正点原子2.8寸LCD模块"></a><font size=3>1. 正点原子2.8寸LCD模块</font></h2><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520165852112.png" alt="image-20230520165852112" style="zoom:50%;" />

<p>上图是正点原子的2.8寸LCD模块的原理图，说真的，没看懂，不明白为什么模块原理图上跳过了D8和D9两根线，并且标号对应的时候要D0对应DB1这样子。这个图给我看自闭了，反正是没看懂，而且教程也没见说为什么这样。索性不看了，目前就看几个关键的引脚，这几个关键的引脚标号对就行：</p>
<table>
<thead>
<tr>
<th>类型</th>
<th>STM32引脚</th>
<th>LCD引脚</th>
<th>ILI9341</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>8080总线</td>
<td>FSMC_NE4</td>
<td>LCD_CS</td>
<td>CSX</td>
<td>PG12，LCD片选信号</td>
</tr>
<tr>
<td>8080总线</td>
<td>FSMC_NOE</td>
<td>LCD_RD</td>
<td>RDX</td>
<td>PD4，读使能信号</td>
</tr>
<tr>
<td>8080总线</td>
<td>FSMC_NEW</td>
<td>LCD_WR</td>
<td>WRX</td>
<td>PD5，写使能信号</td>
</tr>
<tr>
<td>8080总线</td>
<td>FSMC_A10</td>
<td>LCD_RS</td>
<td>D&#x2F;CX</td>
<td>PG0，命令&#x2F;数据切换信号</td>
</tr>
<tr>
<td>8080总线</td>
<td>FSMC_D[15:0]</td>
<td>—</td>
<td>—</td>
<td>16位双向数据线</td>
</tr>
<tr>
<td>复位</td>
<td>NRST</td>
<td>LCD_RST</td>
<td>—</td>
<td>硬件复位信号</td>
</tr>
<tr>
<td>背光</td>
<td>GPIO_A0</td>
<td>LCD_BL</td>
<td>—</td>
<td>背光控制（高电平点亮，低电平熄灭）</td>
</tr>
</tbody></table>
<p>额，去看了一眼ILI9341的接口模式，突然发现原来还有另一种8080时序，用的数据线是D[17:10]和D[8:1]，这就跟正点原子的屏幕对应起来了，绝了。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520172732803.png" alt="image-20230520172732803" style="zoom:50%;" />

<h2 id="2-韦东山LCD屏模块"><a href="#2-韦东山LCD屏模块" class="headerlink" title="2. 韦东山LCD屏模块"></a><font size=3>2. 韦东山LCD屏模块</font></h2><p>下边是韦东山的开发板的LCD模块相关原理图，作为参考吧，最后驱动还是用的正点原子的屏幕。</p>
<ul>
<li>LCD底板原理图</li>
</ul>
<p><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520172347644.png" alt="image-20230520172347644"></p>
<ul>
<li>LCD模块原理图</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520172426959.png" alt="image-20230520172426959" style="zoom:50%;" />

<h1 id="二、STM32CubeMX配置"><a href="#二、STM32CubeMX配置" class="headerlink" title="二、STM32CubeMX配置"></a><font size=3>二、STM32CubeMX配置</font></h1><h2 id="1-FSMC配置"><a href="#1-FSMC配置" class="headerlink" title="1. FSMC配置"></a><font size=3>1. FSMC配置</font></h2><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520193526299.png" alt="image-20230520193526299" style="zoom:50%;" />

<p>这里跟FSMC驱动SRAM的配置界面在同一个位置，我们这里按照上图配置即可。这里主要关注②、③、④和⑤的配置，关于模式和时间配置可以看下一个小节的笔记，会专门分析。</p>
<h2 id="2-LCD背光引脚配置"><a href="#2-LCD背光引脚配置" class="headerlink" title="2. LCD背光引脚配置"></a><font size=3>2. LCD背光引脚配置</font></h2><p>背光就是一个普通的GPIO引脚，根据硬件电路图，背光引脚高电平将会点亮屏幕，低电平将会熄灭屏幕：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520190749494.png" alt="image-20230520190749494" style="zoom:50%;" />

<h2 id="3-时钟树配置"><a href="#3-时钟树配置" class="headerlink" title="3. 时钟树配置"></a><font size=3>3. 时钟树配置</font></h2><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520190833399.png" alt="image-20230520190833399" style="zoom:50%;" />

<h2 id="4-FSMC时序参数配置"><a href="#4-FSMC时序参数配置" class="headerlink" title="4. FSMC时序参数配置"></a><font size=3>4. FSMC时序参数配置</font></h2><h3 id="4-1-ILI9341时序参数图"><a href="#4-1-ILI9341时序参数图" class="headerlink" title="4.1 ILI9341时序参数图"></a><font size=3>4.1 ILI9341时序参数图</font></h3><p>注意这里我们看8080的第二种模式的时序图，因为前边看硬件原理图的话，发现使用的是8080-II模式，我们看一下<a href="STM32%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3%E8%B5%84%E6%96%99/02%E6%98%BE%E7%A4%BA%E5%B1%8F%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/TFTLCD%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/01ILI9341_DS.pdf">01ILI9341_DS.pdf</a>的18.3.2 Display Parallel 18&#x2F;16&#x2F;9&#x2F;8-bit Interface Timing Characteristics(8080-Ⅱ system) ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520192619072.png" alt="image-20230520192619072" style="zoom:80%;" />

<p>我们再来看一下ILI9341时序参数的要求：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520192825396.png" alt="image-20230520192825396" style="zoom:50%;" />

<p>ILI9341 时序参数说明及要求可大致得知 ILI9341 的写周期为最小 twc &#x3D; 66ns，而读周期最小为 trdl+trod&#x3D;45+20&#x3D;65ns。（对于读周期表中有参数要一个要求为 trcfm 和 trc 分别为 450ns 及 160ns，但经过测试并不需要遵照它们的指标要求）  </p>
<p>结合 ILI9341 的时序要求和 FSMC 的配置图，代码中按照读写时序周期均要求至少 66ns 来计算，配置结果为 ADDSET &#x3D; 1 及 DATST &#x3D; 4，把时间单位 1&#x2F;72 微秒 (即 1000&#x2F;72 纳秒) 代入，因此读写周期的时间被配置为  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">读周期： trc =((ADDSET+<span class="number">1</span>)+(DATST+<span class="number">1</span>)+<span class="number">2</span>) *<span class="number">1000</span>/<span class="number">72</span> = ((<span class="number">1</span>+<span class="number">1</span>)+(<span class="number">4</span>+<span class="number">1</span>)+<span class="number">2</span>)*<span class="number">1000</span>/<span class="number">72</span> = <span class="number">125</span>ns</span><br><span class="line">写周期： twc =((ADDSET+<span class="number">1</span>)+(DATST+<span class="number">1</span>)) *<span class="number">1000</span>/<span class="number">72</span> = ((<span class="number">1</span>+<span class="number">1</span>)+(<span class="number">4</span>+<span class="number">1</span>))*<span class="number">1000</span>/<span class="number">72</span> = <span class="number">97</span>ns</span><br></pre></td></tr></table></figure>

<p>所以把这两个参数值写入到 FSMC 后，它控制的读写周期都比 ILI9341 的最低要求值大。（经测试，这两个参数值也可以适当减小）  </p>
<h3 id="4-2-参数的确定"><a href="#4-2-参数的确定" class="headerlink" title="4.2 参数的确定"></a><font size=3>4.2 参数的确定</font></h3><p>其实到这里我就没有去计算了，直接用的教程里边的了，这里开起了扩展模式，因为读写时序似乎有些不一样：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520193711597.png" alt="image-20230520193711597" style="zoom:50%;" />

<h1 id="三、LCD基本驱动实现"><a href="#三、LCD基本驱动实现" class="headerlink" title="三、LCD基本驱动实现"></a><font size=3>三、LCD基本驱动实现</font></h1><h2 id="1-相关定义"><a href="#1-相关定义" class="headerlink" title="1. 相关定义"></a><font size=3>1. 相关定义</font></h2><h3 id="1-D-C地址确定"><a href="#1-D-C地址确定" class="headerlink" title="1. D&#x2F;C地址确定"></a><font size=3>1. D&#x2F;C地址确定</font></h3><p>D&#x2F;CX输出<strong>高电平的地址，即可控制表示数据</strong>， 输出<strong>低电平的地址，即可控制表示命令</strong>。  </p>
<h4 id="1-1-结构体偏移方式"><a href="#1-1-结构体偏移方式" class="headerlink" title="1.1 结构体偏移方式"></a><font size=3>1.1 结构体偏移方式</font></h4><p>我们前边知道TFTLCD 的 D&#x2F;C 接在 FSMC的 A10 上面， CS 接在 FSMC_NE4 上，并且是 16 位数据总线。 即我们使用的是 FSMC 存储器1 的第 4 区，我们定义如下 LCD 操作结构体： </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// LCD地址结构体</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    __IO <span class="type">uint16_t</span> ILI9341_CMD_Addr;</span><br><span class="line">    __IO <span class="type">uint16_t</span> ILI9341_DATA_Addr;</span><br><span class="line">&#125; LCD_TypeDef;</span><br><span class="line"></span><br><span class="line"><span class="comment">//使用NOR/SRAM的 Bank1.sector4,地址位HADDR[27,26]=11 A10作为数据命令区分线 注意设置时STM32内部会右移一位对齐!</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> LCD_FSMC_ADDR_BASE        ((uint32_t)(0x6C000000 | 0x000007FE))</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> LCD                      ((LCD_TypeDef *) LCD_FSMC_ADDR_BASE)</span></span><br></pre></td></tr></table></figure>

<p>（1）FSMC的基地址，这个取决于我们的 LCD_CS接在FSMC_NEx的哪一个线上，这里接在FSMC_NE4，所以起始地址就是0x6c00 0000啦。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230520195047470.png" alt="image-20230520195047470" style="zoom:50%;" />

<p>（2）LCD_FSMC_ADDR_BASE ：这个是我们LCD数据&#x2F;命令控制的地址，前边其实已经介绍过计算方法了，这里接在A10上边，所以，如上边结构体，地址 0X6C00 0000 开始，而 0X0000 07FE，则是 A10 的偏移量。 我们将这个地址强制转换为LCD_TypeDef 结构体地址，那么可以得到 LCD&rarr;ILI9341_CMD_Addr 的地址就是 0X6C00 07FE，对应A10 的状态为 0(即 D&#x2F;C&#x3D;0)，而 LCD&rarr;ILI9341_DATA_Addr的地址就是 0X6C00 0800（结构体地址自增），对应 A10 的状态为 1（即 D&#x2F;C&#x3D;1）。    </p>
<p>（3）这个7FE怎么来的？我猜测是这样算的，首先，我们需要确定地址自增2个字节后，可以实现指定位的0和1的切换，这样的话，显然从0到1的状态是很好找的，因为只要向指定的位进1就可以啦，所以我们找一个第11位为1的地址，就最简单的 0X6C00 0800，那么第11位为0的地址，那这一位减去1不就是了嘛，由于我们定义的结构体成员都是16位的，我们可以减去2，这样更加符合编程习惯。例如，我肯要是定义结构体的地址为“ LCD_TypeDef”的地址为“ 0x6D000000-2”，则成员“ ILI9341_CMD_Addr”地址为“ 0x6D000000-2”，成员“ ILI9341_DATA_Addr”的地址为“ 0x6D000000”，以后访问这两个地址，也是一样的效果，也就可以分别发送命令、数据内容 。</p>
<p>（4）其实上边有一些没有看懂，上边的结构体成员为什么是定义成16位的，按理来说，我们使用的地址格式是32位的，后边看懂了，搞明白为什么了再补充吧。</p>
<h4 id="1-2-直接定义"><a href="#1-2-直接定义" class="headerlink" title="1.2 直接定义"></a><font size=3>1.2 直接定义</font></h4><p>其实吧，上边的结构体定义的方式不是很好找，至少我反正不可能一下子找到刚刚好经过地址递增就能实现指定位的0和1的切换，为什么要那么麻烦呢？我直接定义不行吗？当然可以啦，毕竟只要0X6C00 0000~0X6FFF FFFF 内的任意地址都是可以的，保证11位是0或者1就行啦。</p>
<p>要使 FSMC_A10 地址线为高电平，实质是访问内部 HADDR 地址的第 (10+1) 位为 1 即可，使用 0X6C00 0000~0X6FFF FFFF 内的任意地址，作如下运算：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">使 FSMC_A10 地址线为高电平： <span class="number">0X6C00</span> <span class="number">0000</span> | (<span class="number">1</span> &lt;&lt; (<span class="number">10</span>+<span class="number">1</span>))</span><br></pre></td></tr></table></figure>

<p>要使 FSMC_A10 地址线为低电平，实质是访问内部 HADDR 地址的第 (16+1) 位为 0 即可，使用 0X6C00 0000~0X6FFF FFFF 内的任意地址，作如下运算：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">使 FSMC_A16 地址线为低电平： <span class="number">0X6C00</span> <span class="number">0000</span> &amp;(~ (<span class="number">1</span>&lt;&lt;(<span class="number">10</span>+<span class="number">1</span>))) </span><br></pre></td></tr></table></figure>

<p>所以后边我都定义成如下宏：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/******************************* ILI9341 显示屏的 FSMC 参数定义 ***************************/</span></span><br><span class="line"><span class="comment">//FSMC_Bank1_NORSRAM用于LCD命令操作的地址</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> FSMC_Addr_ILI9341_CMD  ( ( uint32_t )(0X6C000000))</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//FSMC_Bank1_NORSRAM用于LCD数据操作的地址      </span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> FSMC_Addr_ILI9341_DATA ( ( uint32_t )(0X6C000800))</span></span><br></pre></td></tr></table></figure>



<p>【注意】其实吧，通过这种方式计算得来的地址，并不是所有的地址都能用，不能用的时候注意换一个试一下，我测了一下对于这里使用A10的话，最低的4个位不能是奇数，可能是存在一个对齐问题吧。</p>
<h3 id="1-2-颜色定义"><a href="#1-2-颜色定义" class="headerlink" title="1.2 颜色定义"></a><font size=3>1.2 颜色定义</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">define</span> WHITE           0xFFFF</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> BLACK           0x0000</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> BLUE            0x001F</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> BRED            0XF81F</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> GRED            0XFFE0</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> GBLUE           0X07FF</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> RED             0xF800</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> MAGENTA         0xF81F</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> GREEN           0x07E0</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CYAN            0x7FFF</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> YELLOW          0xFFE0</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> BROWN           0XBC40  <span class="comment">//棕色</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> BRRED           0XFC07  <span class="comment">//棕红色</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> GRAY            0X8430  <span class="comment">//灰色</span></span></span><br></pre></td></tr></table></figure>

<p>我们使用的是RGB565，颜色为16位。</p>
<h3 id="1-3-LCD参数结构体"><a href="#1-3-LCD参数结构体" class="headerlink" title="1.3 LCD参数结构体"></a><font size=3>1.3 LCD参数结构体</font></h3><p>为了管理LCD的各项参数，我们定一个了一个结构体来配置一些全局参数，作何用途，后边实例会有。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    <span class="type">uint16_t</span> id;           <span class="comment">// LCD ID</span></span><br><span class="line">    <span class="type">uint8_t</span> LCD_SCAN_MODE; <span class="comment">// LCD 扫描模式，参数可选值为0-7</span></span><br><span class="line">    <span class="type">uint16_t</span> LCD_X_LENGTH; <span class="comment">// LCD X方向长度</span></span><br><span class="line">    <span class="type">uint16_t</span> LCD_Y_LENGTH; <span class="comment">// LCD Y方向长度</span></span><br><span class="line">    <span class="type">uint16_t</span> PonitColor;   <span class="comment">// LCD 画笔颜色，就是前景色</span></span><br><span class="line">    <span class="type">uint16_t</span> BackColor;    <span class="comment">// LCD 背景颜色</span></span><br><span class="line">&#125; _lcd_dev;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="2-FSMC初始化"><a href="#2-FSMC初始化" class="headerlink" title="2. FSMC初始化"></a><font size=3>2. FSMC初始化</font></h2><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">SRAM_HandleTypeDef hsram2;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* FSMC initialization function */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">MX_FSMC_Init</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">  FSMC_NORSRAM_TimingTypeDef Timing = &#123;<span class="number">0</span>&#125;;</span><br><span class="line">  FSMC_NORSRAM_TimingTypeDef ExtTiming = &#123;<span class="number">0</span>&#125;;</span><br><span class="line">  <span class="comment">/** Perform the SRAM2 memory initialization sequence</span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line">  hsram2.Instance = FSMC_NORSRAM_DEVICE;</span><br><span class="line">  hsram2.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;</span><br><span class="line">  <span class="comment">/* hsram2.Init */</span></span><br><span class="line">  hsram2.Init.NSBank = FSMC_NORSRAM_BANK4;</span><br><span class="line">  hsram2.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;</span><br><span class="line">  hsram2.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;</span><br><span class="line">  hsram2.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;</span><br><span class="line">  hsram2.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;</span><br><span class="line">  hsram2.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;</span><br><span class="line">  hsram2.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;</span><br><span class="line">  hsram2.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;</span><br><span class="line">  hsram2.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;</span><br><span class="line">  hsram2.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;</span><br><span class="line">  hsram2.Init.ExtendedMode = FSMC_EXTENDED_MODE_ENABLE;</span><br><span class="line">  hsram2.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;</span><br><span class="line">  hsram2.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;</span><br><span class="line">  <span class="comment">/* Timing */</span></span><br><span class="line">  Timing.AddressSetupTime = <span class="number">0x06</span>;</span><br><span class="line">  Timing.AddressHoldTime = <span class="number">15</span>;</span><br><span class="line">  Timing.DataSetupTime = <span class="number">26</span>;</span><br><span class="line">  Timing.BusTurnAroundDuration = <span class="number">15</span>;</span><br><span class="line">  Timing.CLKDivision = <span class="number">16</span>;</span><br><span class="line">  Timing.DataLatency = <span class="number">17</span>;</span><br><span class="line">  Timing.AccessMode = FSMC_ACCESS_MODE_A;</span><br><span class="line">  <span class="comment">/* ExtTiming */</span></span><br><span class="line">  ExtTiming.AddressSetupTime = <span class="number">3</span>;</span><br><span class="line">  ExtTiming.AddressHoldTime = <span class="number">15</span>;</span><br><span class="line">  ExtTiming.DataSetupTime = <span class="number">0x06</span>;</span><br><span class="line">  ExtTiming.BusTurnAroundDuration = <span class="number">15</span>;</span><br><span class="line">  ExtTiming.CLKDivision = <span class="number">16</span>;</span><br><span class="line">  ExtTiming.DataLatency = <span class="number">17</span>;</span><br><span class="line">  ExtTiming.AccessMode = FSMC_ACCESS_MODE_A;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">if</span> (HAL_SRAM_Init(&amp;hsram2, &amp;Timing, &amp;ExtTiming) != HAL_OK)</span><br><span class="line">  &#123;</span><br><span class="line">    Error_Handler( );</span><br><span class="line">  &#125;</span><br><span class="line">  __HAL_AFIO_FSMCNADV_DISCONNECTED();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>我是再FSMC驱动SRAM的工程中添加的LCD，所以这里命名的时候是hsram2，具体的成员赋值这里就不写了，跟前边其实都差不多。</p>
<h2 id="3-GPIO初始化"><a href="#3-GPIO初始化" class="headerlink" title="3. GPIO初始化"></a><font size=3>3. GPIO初始化</font></h2><p>这里应该有FSMC所使用的所有引脚的初始化，但是由于是STM32CubeMX生成的，所以这里就不详细写了，写一下背光的初始化代码吧：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> <span class="title function_">MX_GPIO_Init</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">  GPIO_InitTypeDef GPIO_InitStruct = &#123;<span class="number">0</span>&#125;;</span><br><span class="line">  <span class="comment">/* GPIO Ports Clock Enable */</span></span><br><span class="line">  __HAL_RCC_GPIOB_CLK_ENABLE();</span><br><span class="line">  <span class="comment">/*Configure GPIO pin Output Level */</span></span><br><span class="line">  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);</span><br><span class="line">  <span class="comment">/*Configure GPIO pins : PB0 PB5 */</span></span><br><span class="line">  GPIO_InitStruct.Pin = GPIO_PIN_0;</span><br><span class="line">  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;</span><br><span class="line">  GPIO_InitStruct.Pull = GPIO_PULLUP;</span><br><span class="line">  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;</span><br><span class="line">  HAL_GPIO_Init(GPIOB, &amp;GPIO_InitStruct);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="4-读写函数实现"><a href="#4-读写函数实现" class="headerlink" title="4. 读写函数实现"></a><font size=3>4. 读写函数实现</font></h2><h3 id="4-1-向ILI9341写入命令"><a href="#4-1-向ILI9341写入命令" class="headerlink" title="4.1 向ILI9341写入命令"></a><font size=3>4.1 向ILI9341写入命令</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  向ILI9341写入命令</span></span><br><span class="line"><span class="comment">  * @param  usCmd :要写入的命令（寄存器地址）</span></span><br><span class="line"><span class="comment">  * @retval 无</span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">ILI9341_Write_Cmd</span><span class="params">(<span class="type">uint16_t</span> usCmd)</span></span><br><span class="line">&#123;</span><br><span class="line">    * (__IO <span class="type">uint16_t</span> *) (FSMC_Addr_ILI9341_CMD) = usCmd;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>【函数说明】</strong>向ILI9341写入命令。</p>
<p><strong>【参数说明】</strong></p>
<ul>
<li>usCmd ：要写入的命令（寄存器地址）。</li>
</ul>
<h3 id="4-2-向ILI9341写入数据"><a href="#4-2-向ILI9341写入数据" class="headerlink" title="4.2 向ILI9341写入数据"></a><font size=3>4.2 向ILI9341写入数据</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  向ILI9341写入数据</span></span><br><span class="line"><span class="comment">  * @param  usData :要写入的数据</span></span><br><span class="line"><span class="comment">  * @retval 无</span></span><br><span class="line"><span class="comment">  */</span>	</span><br><span class="line"> <span class="type">void</span> <span class="title function_">ILI9341_Write_Data</span> <span class="params">(<span class="type">uint16_t</span> usData)</span></span><br><span class="line">&#123;</span><br><span class="line">	* ( __IO <span class="type">uint16_t</span> * ) (FSMC_Addr_ILI9341_DATA) = usData;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>【函数说明】</strong>向ILI9341写入数据。</p>
<p><strong>【参数说明】</strong></p>
<ul>
<li>usData ：要写入的数据。</li>
</ul>
<h3 id="4-3-从ILI9341读取数据"><a href="#4-3-从ILI9341读取数据" class="headerlink" title="4.3 从ILI9341读取数据"></a><font size=3>4.3 从ILI9341读取数据</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  从ILI9341读取数据</span></span><br><span class="line"><span class="comment">  * @param  无</span></span><br><span class="line"><span class="comment">  * @retval 读取到的数据</span></span><br><span class="line"><span class="comment">  */</span>	</span><br><span class="line"><span class="type">uint16_t</span> <span class="title function_">ILI9341_Read_Data</span> <span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">return</span> ( * (__IO <span class="type">uint16_t</span> *) (FSMC_Addr_ILI9341_DATA) );</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>【函数说明】</strong>向ILI9341写入命令。</p>
<p><strong>【参数说明】</strong></p>
<h3 id="4-4-读取ILI9341-ID"><a href="#4-4-读取ILI9341-ID" class="headerlink" title="4.4 读取ILI9341 ID"></a><font size=3>4.4 读取ILI9341 ID</font></h3><p>我们来看一下0xD3命令，<a href="STM32%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3%E8%B5%84%E6%96%99/02%E6%98%BE%E7%A4%BA%E5%B1%8F%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/TFTLCD%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/01ILI9341_DS.pdf">01ILI9341_DS.pdf</a>的8.3.23. Read ID4 (D3h) ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521102921252.png" alt="image-20230521102921252" style="zoom: 67%;" />

<p>可以看到，我们向ILI9341写入0xD3命令后，ILI9341会返回4个字节数据，其中第三和第四字节的数据组合起来就是ILI9341的ID，所以读取ID的函数实现下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> <span class="title function_">ILI9341_ID_Read</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">uint16_t</span> id = <span class="number">0</span>;</span><br><span class="line">	<span class="comment">// 显示一下LCD的命令和数据地址</span></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;FSMC_Addr_ILI9341_CMD :0x%X\r\n&quot;</span>, FSMC_Addr_ILI9341_CMD);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;FSMC_Addr_ILI9341_DATA:0x%X\r\n&quot;</span>, FSMC_Addr_ILI9341_DATA);</span><br><span class="line"></span><br><span class="line">	ILI9341_Write_Cmd(<span class="number">0xD3</span>);</span><br><span class="line">	id = ILI9341_Read_Data();<span class="comment">// dummy read</span></span><br><span class="line">	id = ILI9341_Read_Data();<span class="comment">// 读到0X00</span></span><br><span class="line">	id = ILI9341_Read_Data();<span class="comment">// 读取0X93</span></span><br><span class="line">	id &lt;&lt;= <span class="number">8</span>;</span><br><span class="line">	id |= ILI9341_Read_Data();<span class="comment">// 读取0X41</span></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;id:%#x\r\n&quot;</span>, id);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>最后串口调试助手的打印信息如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">FSMC_Addr_ILI9341_CMD :<span class="number">0x6C000002</span></span><br><span class="line">FSMC_Addr_ILI9341_DATA:<span class="number">0x6C000800</span></span><br><span class="line">id:<span class="number">0x9341</span></span><br></pre></td></tr></table></figure>

<h3 id="4-5-IO问题"><a href="#4-5-IO问题" class="headerlink" title="4.5 __IO问题"></a><font size=3>4.5 __IO问题</font></h3><p>上边读写函数中的__IO是什么？我们追踪一下会发现它其实就是：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">define</span>     __IO    volatile             <span class="comment">/*!&lt; Defines &#x27;read / write&#x27; permissions */</span></span></span><br></pre></td></tr></table></figure>

<p>volatile关键字会提醒编译器，它后面所定义的变量随时都有可能改变，因此编译后的程序每次需要存储或读取这个变量的时候，告诉编译器对该变量不做优化，都会<strong>直接从变量内存地址中读取数据</strong>，从而可以提供对特殊地址的稳定访问。</p>
<p>如果没有volatile关键字，则编译器可能优化读取和存储，可能暂时使用寄存器中的值，如果这个变量由别的程序更新了的话，将出现不一致的现象。（简单的说就是：volatile关键词影响编译器编译的结果，用volatile声明的变量表示该变量随时可能发生变化，与该变量有关的运算，不要进行编译优化，以免出错）。</p>
<p>这个地方就可以做一个测试，我们将上边实现的三个函数的 __IO修饰去掉，然后重新读取ID，会发现串口调试助手打印信息为：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">FSMC_Addr_ILI9341_CMD :<span class="number">0x6C000002</span></span><br><span class="line">FSMC_Addr_ILI9341_DATA:<span class="number">0x6C000800</span></span><br><span class="line">id:<span class="number">0</span></span><br></pre></td></tr></table></figure>

<p>我们刚才可以读取到正确ID的函数读不到数据了，这是为什么？我们分析一下，我们向0x6C000002这个地址写入了一次数据，此时可以触发一次FSMC的数据传输，然后，我们从0x6C000800读取数据，读取的数据被存入寄存器（R1-R15这一类），触发一次FSMC时序，然后我们再读取的时候，还是读的0x6C000800这个地址，这个时候STM32可能直接就从寄存器取了数据，并没有直接从0x6C000800这个地址获取数据，所以就可能出现读取失败的情况，这个猜测没有经过实际验证，不过大概分析一下，理论上应该属这样的。</p>
<p>所以从这个来看，我们想要直接从内存中获取某个变量的数据的话，最好就是加上volatile关键字，以避免不必要的麻烦。</p>
<h1 id="四、LCD寄存器配置"><a href="#四、LCD寄存器配置" class="headerlink" title="四、LCD寄存器配置"></a><font size=3>四、LCD寄存器配置</font></h1><p>上边我们已经完成了对LCD的一个简单的初始化，不出意外的话，上边那些完成后，我们已经可以成功点亮LCD屏幕了，接下来就是对ILI9341的一些配置了。下边所谓的一些寄存器，我在手册没有看懂啊寄存器的相关介绍，但是吧，我感觉其实就是手册上介绍的命令，在内部的存在形式其实应该就是寄存器。</p>
<p>读写LCD的控制器 ILI9341 的寄存器，其实就是通过一系列的命令对ILI9341进行配置，这个时候需要根据ILI9488手册介绍的命令，依次进行配置。但ILI9341命令众多，依次配置效率不高，通常开发中， LCD 屏幕厂商会提供初始化参考代码， 用户直接使用即可。  有一些配置项，需要在初始化完成后就进行配置，一般厂家会直接给，有一些命令是我们操作液晶屏时必须得，这一节笔记涉及的命令在 <a href="STM32%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3%E8%B5%84%E6%96%99/02%E6%98%BE%E7%A4%BA%E5%B1%8F%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/TFTLCD%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/01ILI9341_DS.pdf">01ILI9341_DS.pdf</a> 的 8. Command 一节都有很详细的介绍。下边将会介绍一些我们需要了解的一些命令。</p>
<h2 id="1-屏幕开窗"><a href="#1-屏幕开窗" class="headerlink" title="1. 屏幕开窗"></a><font size=3>1. 屏幕开窗</font></h2><p>根据液晶屏的要求，在发送显示数据前，需要先设置显示窗口确定后面发送的像素数据的显示区域，也就是开窗。</p>
<h3 id="1-1-Column-Address-Set-2Ah"><a href="#1-1-Column-Address-Set-2Ah" class="headerlink" title="1.1 Column Address Set (2Ah) "></a><font size=3>1.1 Column Address Set (2Ah) </font></h3><p>我们可以查看<a href="STM32%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3%E8%B5%84%E6%96%99/02%E6%98%BE%E7%A4%BA%E5%B1%8F%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/TFTLCD%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/01ILI9341_DS.pdf">01ILI9341_DS.pdf</a>的8.2.20. Column Address Set (2Ah)一节，命令的格式如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521155552530.png" alt="image-20230521155552530" style="zoom:80%;" />

<p>2Ah命令设置的列的地址，SC[15:0]表示列地址的起始位置，EC[15:0]表示列地址的结束位置：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521160414233.png" alt="image-20230521160414233" style="zoom: 67%;" />



<p>我们需要发送四个字节的数据，前两个字节表示列地址的起始位置，后两个字节表示列地址的结束为止。</p>
<h3 id="1-2-Page-Address-Set-2Bh"><a href="#1-2-Page-Address-Set-2Bh" class="headerlink" title="1.2 Page Address Set (2Bh)"></a><font size=3>1.2 Page Address Set (2Bh)</font></h3><p>我们可以查看<a href="STM32%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3%E8%B5%84%E6%96%99/02%E6%98%BE%E7%A4%BA%E5%B1%8F%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/TFTLCD%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/01ILI9341_DS.pdf">01ILI9341_DS.pdf</a>的8.2.21. Page Address Set (2Bh)一节，命令格式如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521161239928.png" alt="image-20230521161239928" style="zoom:80%;" />

<p>2Bh命令设置的是行的地址，SP[15:0]表示行地址的起始位置，EP[15:0]表示行地址的结束位置：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521161323673.png" alt="image-20230521161323673" style="zoom: 67%;" />

<h3 id="1-3-开窗函数实现"><a href="#1-3-开窗函数实现" class="headerlink" title="1.3 开窗函数实现"></a><font size=3>1.3 开窗函数实现</font></h3><p>上边两个命令就可以确定一个矩形窗口了，这个窗口我们就可以用于显示数据：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521161945923.png" alt="image-20230521161945923" style="zoom:80%;" />

<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @brief  在ILI9341显示器上开辟一个窗口</span></span><br><span class="line"><span class="comment"> * @param  usX ：在特定扫描方向下窗口的起点X坐标</span></span><br><span class="line"><span class="comment"> * @param  usY ：在特定扫描方向下窗口的起点Y坐标</span></span><br><span class="line"><span class="comment"> * @param  usWidth ：窗口的宽度</span></span><br><span class="line"><span class="comment"> * @param  usHeight ：窗口的高度</span></span><br><span class="line"><span class="comment"> * @retval 无</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">ILI9341_OpenWindow</span><span class="params">(<span class="type">uint16_t</span> usX, <span class="type">uint16_t</span> usY, <span class="type">uint16_t</span> usWidth, <span class="type">uint16_t</span> usHeight)</span></span><br><span class="line">&#123;</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x2A</span>);        <span class="comment">/* 设置X坐标 */</span></span><br><span class="line">    ILI9341_Write_Data(usX &gt;&gt; <span class="number">8</span>);   <span class="comment">/* 起始点的高8位 */</span></span><br><span class="line">    ILI9341_Write_Data(usX &amp; <span class="number">0xff</span>); <span class="comment">/* 起始点的低8位 */</span></span><br><span class="line">    ILI9341_Write_Data((usX + usWidth - <span class="number">1</span>) &gt;&gt; <span class="number">8</span>);  <span class="comment">/* 结束点的高8位 */</span></span><br><span class="line">    ILI9341_Write_Data((usX + usWidth - <span class="number">1</span>) &amp; <span class="number">0xff</span>);<span class="comment">/* 结束点的低8位 */</span></span><br><span class="line"></span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x2B</span>);        <span class="comment">/* 设置Y坐标 */</span></span><br><span class="line">    ILI9341_Write_Data(usY &gt;&gt; <span class="number">8</span>);</span><br><span class="line">    ILI9341_Write_Data(usY &amp; <span class="number">0xff</span>);</span><br><span class="line">    ILI9341_Write_Data((usY + usHeight - <span class="number">1</span>) &gt;&gt; <span class="number">8</span>);</span><br><span class="line">    ILI9341_Write_Data((usY + usHeight - <span class="number">1</span>) &amp; <span class="number">0xff</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="2-设置像素格式"><a href="#2-设置像素格式" class="headerlink" title="2. 设置像素格式"></a><font size=3>2. 设置像素格式</font></h2><h3 id="2-1-COLMOD-Pixel-Format-Set-3Ah"><a href="#2-1-COLMOD-Pixel-Format-Set-3Ah" class="headerlink" title="2.1 COLMOD: Pixel Format Set (3Ah)"></a><font size=3>2.1 COLMOD: Pixel Format Set (3Ah)</font></h3><p>我们可以查看<a href="STM32%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3%E8%B5%84%E6%96%99/02%E6%98%BE%E7%A4%BA%E5%B1%8F%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/TFTLCD%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/01ILI9341_DS.pdf">01ILI9341_DS.pdf</a>的8.2.33. COLMOD: Pixel Format Set (3Ah)一节，命令格式如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521162918219.png" alt="image-20230521162918219" style="zoom:80%;" />

<p>我们可以看到我们发送了3Ah命令后，需要发送一个参数，这个参数是用于设置像素格式，像素格式由DPI[2:0]和DBI[2:0]决定，它们的取值如下表：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521163223952.png" alt="image-20230521163223952" style="zoom:80%;" />

<p>我们使用的屏幕是一般是16位的，我们一般会设置成RGB565格式，所以这里我们需要配置DPI[2:0]为101，DBI[2:0]为101，配合其他的位，我们要发送的数据就是0x55。</p>
<h3 id="2-2-函数实现"><a href="#2-2-函数实现" class="headerlink" title="2.2 函数实现"></a><font size=3>2.2 函数实现</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ILI9341_Write_Cmd(<span class="number">0x3A</span>);</span><br><span class="line">ILI9341_Write_Data(<span class="number">0x55</span>);</span><br></pre></td></tr></table></figure>

<h2 id="3-发送像素数据"><a href="#3-发送像素数据" class="headerlink" title="3. 发送像素数据  "></a><font size=3>3. 发送像素数据  </font></h2><p>调用上面的 ILI9341_OpenWindow 函数设置显示窗口后，再向液晶屏发送像素数据时，这些数据就会直接显示在它设定的窗口位置中。  </p>
<h3 id="3-1-Memory-Write-2Ch"><a href="#3-1-Memory-Write-2Ch" class="headerlink" title="3.1 Memory Write (2Ch)"></a><font size=3>3.1 Memory Write (2Ch)</font></h3><p>我们可以查看<a href="STM32%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3%E8%B5%84%E6%96%99/02%E6%98%BE%E7%A4%BA%E5%B1%8F%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/TFTLCD%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/01ILI9341_DS.pdf">01ILI9341_DS.pdf</a>的8.2.22. Memory Write (2Ch) 一节，命令格式如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521163832776.png" alt="image-20230521163832776" style="zoom:80%;" />

<p>发送像素数据的命令很简单，首先发送命令代码 0x2C，然后后面紧跟着要传输的像素数据即可。按照我使用的液晶屏的配置，像素点的格式为 RGB565，所以像素数据就是要显示的 RGB565 格式的颜色值。  </p>
<h3 id="3-2-函数实现"><a href="#3-2-函数实现" class="headerlink" title="3.2 函数实现"></a><font size=3>3.2 函数实现</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @brief  在ILI9341显示器上以某一颜色填充像素点</span></span><br><span class="line"><span class="comment"> * @param  ulAmout_Point ：要填充颜色的像素点的总数目</span></span><br><span class="line"><span class="comment"> * @param  usColor ：颜色</span></span><br><span class="line"><span class="comment"> * @retval 无</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="type">static</span> __inline <span class="type">void</span> <span class="title function_">ILI9341_FillColor</span><span class="params">(<span class="type">uint32_t</span> ulAmout_Point, <span class="type">uint16_t</span> usColor)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">uint32_t</span> i = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* memory write */</span></span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x2C</span>);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; ulAmout_Point; i++)</span><br><span class="line">    &#123;</span><br><span class="line">        ILI9341_Write_Data(usColor);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="4-电源模式"><a href="#4-电源模式" class="headerlink" title="4. 电源模式"></a><font size=3>4. 电源模式</font></h2><p>其实有了上边三条命令之后，我们就可以画出一个实心的矩形了，但是后来经过测试，没有效果，发现原来是ILI9341默认是休眠模式，我们需要让它退出休眠模式才可以。</p>
<h3 id="4-1-模式状态读取"><a href="#4-1-模式状态读取" class="headerlink" title="4.1 模式状态读取"></a><font size=3>4.1 模式状态读取</font></h3><h4 id="4-1-1-Read-Display-Power-Mode-0Ah"><a href="#4-1-1-Read-Display-Power-Mode-0Ah" class="headerlink" title="4.1.1 Read Display Power Mode (0Ah) "></a><font size=3>4.1.1 Read Display Power Mode (0Ah) </font></h4><p>我们可以查看<a href="STM32%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3%E8%B5%84%E6%96%99/02%E6%98%BE%E7%A4%BA%E5%B1%8F%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/TFTLCD%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/01ILI9341_DS.pdf">01ILI9341_DS.pdf</a>的8.2.5. Read Display Power Mode (0Ah)一节，命令格式如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521170257692.png" alt="image-20230521170257692" style="zoom:80%;" />

<p>这个命令可以用于读取LCD显示屏当前显示状态，如下表所示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230521170405650.png" alt="image-20230521170405650" style="zoom:80%;" />

<p>我们可以关注一下D2和D4，一个表示是否开启了显示，一个表示是否处于休眠模式。</p>
<h4 id="4-1-2-函数实现"><a href="#4-1-2-函数实现" class="headerlink" title="4.1.2 函数实现"></a><font size=3>4.1.2 函数实现</font></h4><p>我们可以下一个函数用于读取各个状态，来看一下最开始的时候LCD显示屏是什么样的：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  读取LCD电源状态</span></span><br><span class="line"><span class="comment">  * @note   </span></span><br><span class="line"><span class="comment">  * @param  </span></span><br><span class="line"><span class="comment">  * @retval 读取到的状态</span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">uint16_t</span> <span class="title function_">ILI9341_PowerStatus_Read</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">uint16_t</span> power_status = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x0A</span>);</span><br><span class="line">    power_status = ILI9341_Read_Data(); <span class="comment">// dummy read</span></span><br><span class="line">    power_status = ILI9341_Read_Data(); <span class="comment">// 读到0X00</span></span><br><span class="line"></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;power_status:0x%X\r\n&quot;</span>, power_status);</span><br><span class="line">    <span class="keyword">return</span> power_status;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="4-1-3-效果测试"><a href="#4-1-3-效果测试" class="headerlink" title="4.1.3 效果测试"></a><font size=3>4.1.3 效果测试</font></h4><p>我们写一个测试函数，来看一下状态：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> <span class="title function_">LCD_Test</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">    ILI9341_PowerStatus_Read();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>然后我们烧写写到单片机，会有如下打印：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">power_status:0x8</span><br></pre></td></tr></table></figure>

<p>我们换算成二进制就是 0000 1000，除了D[3]为1，其余为0，D[2]表示显示的开关，为0表示目前处于关闭显示状态，D[4]表示休眠模式，为0表示正在休眠模式。所以我们知道，一上电，还未对这个LCD模块做任何配置的情况下，是出于休眠模式和关闭显示状态的，经过后边的测试，得到一个结论，就是我们要想进行显示，需要退出休眠模式，打开显示。</p>
<h3 id="4-2-Sleep-In-Out-Mode"><a href="#4-2-Sleep-In-Out-Mode" class="headerlink" title="4.2 Sleep In&#x2F;Out Mode"></a><font size=3>4.2 Sleep In&#x2F;Out Mode</font></h3><p>我们可以查看<a href="STM32%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3%E8%B5%84%E6%96%99/02%E6%98%BE%E7%A4%BA%E5%B1%8F%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/TFTLCD%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/01ILI9341_DS.pdf">01ILI9341_DS.pdf</a>的8.2.11. Enter Sleep Mode (10h)和8.2.12. Sleep Out (11h) 两节，命令格式如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230522072202116.png" alt="image-20230522072202116" style="zoom: 80%;" />

<p>我们看到，这两个命令是没有参数返回的，我们只需要下发对应的命令即可。我们发送10h命令，lcd就会进入休眠模式，发送11h，就会退出休眠模式。</p>
<p>当模块已进入非休眠模式时，命令11h无效。需要注意的是在发送下一个命令（10h或者11h）之前需要等待5ms，这是为了让电源电压和时钟电路稳定，显示模块会在这5毫秒内进行自诊断功能。这里好像有一个时间要求，一开始若是处于Sleep Out模式，然后发送Sleep In命令进入休眠模式，然后需要等待120msec才能再次发送Sleep Out命令。</p>
<h3 id="4-3-Display-ON-OFF"><a href="#4-3-Display-ON-OFF" class="headerlink" title="4.3 Display ON&#x2F;OFF"></a><font size=3>4.3 Display ON&#x2F;OFF</font></h3><p>我们可以查看<a href="STM32%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3%E8%B5%84%E6%96%99/02%E6%98%BE%E7%A4%BA%E5%B1%8F%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/TFTLCD%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/01ILI9341_DS.pdf">01ILI9341_DS.pdf</a>的8.2.18. Display OFF (28h)和8.2.19. Display ON (29h) 两节，命令格式如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230523123321969.png" alt="image-20230523123321969" style="zoom: 67%;" />

<p>28h命令用于进入DISPLAY OFF模式。在这种模式下，帧内存的输出被禁用并插入空白页。</p>
<p>29h命令用于从DISPLAY OFF模式中恢复。帧内存输出被启用。</p>
<h3 id="4-4-电源模式配置"><a href="#4-4-电源模式配置" class="headerlink" title="4.4 电源模式配置"></a><font size=3>4.4 电源模式配置</font></h3><p>有了上班的几条命令，我们在开机的时候需要配置LCD为Sleep Out Mode和Display ON：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ILI9341_Write_Cmd(<span class="number">0x11</span>);       <span class="comment">// Exit Sleep</span></span><br><span class="line">HAL_Delay(<span class="number">120</span>);</span><br><span class="line">ILI9341_Write_Cmd(<span class="number">0x29</span>);       <span class="comment">// display on</span></span><br></pre></td></tr></table></figure>

<p>我们可以修改测试函数如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> <span class="title function_">LCD_Test</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">    ILI9341_ID_Read();</span><br><span class="line">    ILI9341_PowerStatus_Read();</span><br><span class="line"></span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x11</span>);       <span class="comment">// Exit Sleep</span></span><br><span class="line">    HAL_Delay(<span class="number">120</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x29</span>);       <span class="comment">// display on</span></span><br><span class="line"></span><br><span class="line">    ILI9341_PowerStatus_Read();</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>最后串口打印信息如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">FSMC_Addr_ILI9341_CMD :0x6C000000</span><br><span class="line">FSMC_Addr_ILI9341_DATA:0x6C000800</span><br><span class="line">id:0x9341</span><br><span class="line">power_status:0x8</span><br><span class="line">power_status:0x9C</span><br></pre></td></tr></table></figure>

<p>0x9C就是1001 1100，0x8就是0000 1000可以看到我们执行了两条命令之后，状态从0000 1000变成了1001 1100，D[2]表表示显示开关，配置为1，D[4]表示休眠模式，配置为0表示退出休眠模式。</p>
<h2 id="5-设置液晶的扫描方向"><a href="#5-设置液晶的扫描方向" class="headerlink" title="5. 设置液晶的扫描方向  "></a><font size=3>5. 设置液晶的扫描方向  </font></h2><p>当设置了液晶显示窗口，再连续向液晶屏写入像素点时，它会一个点一个点地往液晶屏的 X 方向填充，填充完一行 X 方向的像素点后，向 Y 方向下移一行， X 坐标回到起始位置，再往 X 方向一个点一个点地填充，如此循环直至填充完整个显示窗口。屏幕的坐标原点和 XY 方向都可以根据实际需要使用相应的命令来配置的。</p>
<h3 id="5-1-Memory-Access-Control-36h"><a href="#5-1-Memory-Access-Control-36h" class="headerlink" title="5.1 Memory Access Control (36h)"></a><font size=3>5.1 Memory Access Control (36h)</font></h3><h4 id="5-1-1-命令格式"><a href="#5-1-1-命令格式" class="headerlink" title="5.1.1 命令格式"></a><font size=3>5.1.1 命令格式</font></h4><p>我们可以查看<a href="STM32%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3%E8%B5%84%E6%96%99/02%E6%98%BE%E7%A4%BA%E5%B1%8F%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/TFTLCD%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/01ILI9341_DS.pdf">01ILI9341_DS.pdf</a>的8.2.29. Memory Access Control (36h)一节，命令格式如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230523130810838.png" alt="image-20230523130810838" style="zoom:80%;" />

<p>Memory Access Control命令参数的Bit[7:5]三位一起控制内存的读写方向。 MY（ Bit[7]） 控制行地址顺序，MX（ Bit[6]）控制列地址顺序， MV（ Bit[5]）控制行列交换 。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230523131019129.png" alt="image-20230523131019129" style="zoom:67%;" />

<p>0X36 命令参数中的 MY、 MX、 MV 这三个数据位用于配置扫描方向，因此一共有 2^3 &#x3D; 8 种模式。其实这个ILI9341控制的液晶屏是240列，320行的，也就是说其实正常来看是按一个竖屏来的。</p>
<h4 id="5-1-2-MH-Horizontal-Refresh-ORDER"><a href="#5-1-2-MH-Horizontal-Refresh-ORDER" class="headerlink" title="5.1.2 MH(Horizontal Refresh ORDER)"></a><font size=3>5.1.2 MH(Horizontal Refresh ORDER)</font></h4><p>MH位控制的就是LCD水平刷新方向。左上角位坐标（0，0）的话，水平方向有240列，当MH为0 的时候是从左到右刷新，当MH为1的时候是从右到左刷新。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230523220742912.png" alt="image-20230523220742912" style="zoom: 50%;" />

<h4 id="5-1-3-ML-Vertical-Refresh-Order"><a href="#5-1-3-ML-Vertical-Refresh-Order" class="headerlink" title="5.1.3 ML(Vertical Refresh Order)"></a><font size=3>5.1.3 ML(Vertical Refresh Order)</font></h4><p>ML位控制的就是LCD垂直刷新方向。左上角位坐标（0，0）的话，垂直方向有320行，当ML为 0 的时候是从上到下刷新，当ML为1的时候从下到上刷新。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524220030511.png" alt="image-20230524220030511" style="zoom:50%;" />

<h4 id="5-1-4-MY、MX和MV"><a href="#5-1-4-MY、MX和MV" class="headerlink" title="5.1.4 MY、MX和MV"></a><font size=3>5.1.4 MY、MX和MV</font></h4><p>这三个位控制着液晶屏的扫描方向，这个表在上一节已经学习过了：</p>
<table>
<thead>
<tr>
<th align="center">B[7:5]</th>
<th align="center">D[7:5]</th>
<th align="center">MY</th>
<th align="center">MX</th>
<th align="center">MV</th>
<th align="center">D[7:5]十进制</th>
<th align="center">模式说明</th>
<th align="center">图片对应</th>
</tr>
</thead>
<tbody><tr>
<td align="center">000</td>
<td align="center">000</td>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">Normal</td>
<td align="center"><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524133046886.png" alt="image-20230524133046886" style="zoom:67%;" /></td>
</tr>
<tr>
<td align="center">001</td>
<td align="center">001</td>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">X-Y Exchange</td>
<td align="center"><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524133125714.png" alt="image-20230524133125714" style="zoom:67%;" /></td>
</tr>
<tr>
<td align="center">010</td>
<td align="center">010</td>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">2</td>
<td align="center">X-Mirror</td>
<td align="center"><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524133202987.png" alt="image-20230524133202987" style="zoom:67%;" /></td>
</tr>
<tr>
<td align="center">011</td>
<td align="center">011</td>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">3</td>
<td align="center">XY Exchange X-Mirror</td>
<td align="center"><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524215000828.png" alt="image-20230524215000828" style="zoom:67%;" /></td>
</tr>
<tr>
<td align="center">100</td>
<td align="center">100</td>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">4</td>
<td align="center">Y-Mirror</td>
<td align="center"><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524215142332.png" alt="image-20230524215142332" style="zoom:67%;" /></td>
</tr>
<tr>
<td align="center">101</td>
<td align="center">101</td>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">5</td>
<td align="center">X-Y Exchange Y-Mirror</td>
<td align="center"><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524215313557.png" alt="image-20230524215313557" style="zoom:67%;" /></td>
</tr>
<tr>
<td align="center">110</td>
<td align="center">110</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">6</td>
<td align="center">X&#x2F;Y-Mirror</td>
<td align="center"><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524215421446.png" alt="image-20230524215421446" style="zoom:67%;" /></td>
</tr>
<tr>
<td align="center">111</td>
<td align="center">111</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">7</td>
<td align="center">XY Exchange XY-Mirror</td>
<td align="center"><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524215619493.png" alt="image-20230524215619493" style="zoom:67%;" /></td>
</tr>
</tbody></table>
<p>其中0、3、5、6 模式适合从左至右显示文字，不推荐使用其它模式显示文字  其它模式显示文字会有镜像效果    其中0、2、4、6 模式的X方向像素为240，Y方向像素为320，其中1、3、5、7 模式下X方向像素为320，Y方向像素为240。分成这两类主要是按是否交换XY来的：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230524220303842.png" alt="image-20230524220303842" style="zoom: 50%;" />

<h3 id="5-2-Read-Display-MADCTL-0Bh"><a href="#5-2-Read-Display-MADCTL-0Bh" class="headerlink" title="5.2 Read Display MADCTL (0Bh) "></a><font size=3>5.2 Read Display MADCTL (0Bh) </font></h3><p>上边其实我们看到36h命令配置的是MADCTL这个寄存器，算是一个寄存器把，我们可以通过0Bh来读取当前显示屏的扫描方向相关信息。在<a href="STM32%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3%E8%B5%84%E6%96%99/02%E6%98%BE%E7%A4%BA%E5%B1%8F%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/TFTLCD%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/01ILI9341_DS.pdf">01ILI9341_DS.pdf</a> 的 8.2.6. Read Display MADCTL (0Bh) 一节，命令格式如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230523132641086.png" alt="image-20230523132641086" style="zoom: 80%;" />

<p>相关的位说明如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-26-LCD-04-LCD%E6%98%BE%E7%A4%BA%E5%AE%9E%E7%8E%B0/img/image-20230523132732416.png" alt="image-20230523132732416" style="zoom:50%;" />







<h3 id="5-3-液晶扫描方向实现"><a href="#5-3-液晶扫描方向实现" class="headerlink" title="5.3 液晶扫描方向实现"></a><font size=3>5.3 液晶扫描方向实现</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> <span class="title function_">ILI9341_GramScan</span><span class="params">(<span class="type">uint8_t</span> ucOption)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">// 参数检查，只可输入0-7</span></span><br><span class="line">    <span class="keyword">if</span> (ucOption &gt; <span class="number">7</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 根据模式更新LCD_SCAN_MODE的值，主要用于触摸屏选择计算参数</span></span><br><span class="line">    lcd_param.LCD_SCAN_MODE = ucOption;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 根据模式更新XY方向的像素宽度</span></span><br><span class="line">    <span class="keyword">if</span> (ucOption % <span class="number">2</span> == <span class="number">0</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">// 0 2 4 6模式下X方向像素宽度为240，Y方向为320</span></span><br><span class="line">        lcd_param.LCD_X_LENGTH = ILI9341_LESS_PIXEL;</span><br><span class="line">        lcd_param.LCD_Y_LENGTH = ILI9341_MORE_PIXEL;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">// 1 3 5 7模式下X方向像素宽度为320，Y方向为240</span></span><br><span class="line">        lcd_param.LCD_X_LENGTH = ILI9341_MORE_PIXEL;</span><br><span class="line">        lcd_param.LCD_Y_LENGTH = ILI9341_LESS_PIXEL;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 0x36命令参数的高3位可用于设置GRAM扫描方向</span></span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x36</span>);</span><br><span class="line">    <span class="keyword">if</span> (lcd_param.id == LCDID_ILI9341)</span><br><span class="line">    &#123;</span><br><span class="line">        ILI9341_Write_Data(<span class="number">0x08</span> | (ucOption &lt;&lt; <span class="number">5</span>)); <span class="comment">// 根据ucOption的值设置LCD参数，共0-7种模式</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span> (lcd_param.id == LCDID_ST7789V)</span><br><span class="line">    &#123;</span><br><span class="line">        ILI9341_Write_Data(<span class="number">0x00</span> | (ucOption &lt;&lt; <span class="number">5</span>)); <span class="comment">// 根据ucOption的值设置LCD参数，共0-7种模式</span></span><br><span class="line">    &#125;</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x2A</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);                             <span class="comment">/* x 起始坐标高8位 */</span></span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);                             <span class="comment">/* x 起始坐标低8位 */</span></span><br><span class="line">    ILI9341_Write_Data(((lcd_param.LCD_X_LENGTH - <span class="number">1</span>) &gt;&gt; <span class="number">8</span>) &amp; <span class="number">0xFF</span>); <span class="comment">/* x 结束坐标高8位 */</span></span><br><span class="line">    ILI9341_Write_Data((lcd_param.LCD_X_LENGTH - <span class="number">1</span>) &amp; <span class="number">0xFF</span>);        <span class="comment">/* x 结束坐标低8位 */</span></span><br><span class="line"></span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x2B</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);                             <span class="comment">/* y 起始坐标高8位 */</span></span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);                             <span class="comment">/* y 起始坐标低8位 */</span></span><br><span class="line">    ILI9341_Write_Data(((lcd_param.LCD_Y_LENGTH - <span class="number">1</span>) &gt;&gt; <span class="number">8</span>) &amp; <span class="number">0xFF</span>); <span class="comment">/* y 结束坐标高8位 */</span></span><br><span class="line">    ILI9341_Write_Data((lcd_param.LCD_Y_LENGTH - <span class="number">1</span>) &amp; <span class="number">0xFF</span>);        <span class="comment">/* y 结束坐标低8位 */</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">/* write gram start */</span></span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x2C</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>效果测试还是看后边吧。</p>
<h2 id="6-ILI9341寄存器配置"><a href="#6-ILI9341寄存器配置" class="headerlink" title="6. ILI9341寄存器配置"></a><font size=3>6. ILI9341寄存器配置</font></h2><p>这里贴一下完整的寄存器配置函数：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  ILI9341寄存器配置</span></span><br><span class="line"><span class="comment">  * @note   </span></span><br><span class="line"><span class="comment">  * @param  </span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">ILI9341_Config</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xCF</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0xC1</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0X30</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xED</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x64</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x03</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0X12</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0X81</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xE8</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x85</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x10</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x7A</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xCB</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x39</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x2C</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x34</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x02</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xF7</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x20</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xEA</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xC0</span>);  <span class="comment">// Power control</span></span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x1B</span>); <span class="comment">// VRH[5:0]</span></span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xC1</span>);  <span class="comment">// Power control</span></span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x01</span>); <span class="comment">// SAP[2:0];BT[3:0]</span></span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xC5</span>);  <span class="comment">// VCM control</span></span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x30</span>); <span class="comment">// 3F</span></span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x30</span>); <span class="comment">// 3C</span></span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xC7</span>);  <span class="comment">// VCM control2</span></span><br><span class="line">    ILI9341_Write_Data(<span class="number">0XB7</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x36</span>); <span class="comment">// Memory Access Control</span></span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x48</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x3A</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x55</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xB1</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x1A</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xB6</span>); <span class="comment">// Display Function Control</span></span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x0A</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0xA2</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xF2</span>); <span class="comment">// 3Gamma Function Disable</span></span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x26</span>); <span class="comment">// Gamma curve selected</span></span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x01</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0xE0</span>); <span class="comment">// Set Gamma</span></span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x0F</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x2A</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x28</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x08</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x0E</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x08</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x54</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0XA9</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x43</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x0A</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x0F</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0XE1</span>); <span class="comment">// Set Gamma</span></span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x15</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x17</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x07</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x11</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x06</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x2B</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x56</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x3C</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x05</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x10</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x0F</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x3F</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x3F</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x0F</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x2B</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x01</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x3f</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x2A</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0x00</span>);</span><br><span class="line">    ILI9341_Write_Data(<span class="number">0xef</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x11</span>); <span class="comment">// Exit Sleep</span></span><br><span class="line">    HAL_Delay(<span class="number">120</span>);</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x29</span>); <span class="comment">// display on</span></span><br><span class="line"></span><br><span class="line">    ILI9341_Clear(<span class="number">0</span>, <span class="number">0</span>, lcd_param.LCD_X_LENGTH, lcd_param.LCD_Y_LENGTH);	<span class="comment">/* 清屏，显示全黑 */</span></span><br><span class="line">		</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="7-应用函数"><a href="#7-应用函数" class="headerlink" title="7. 应用函数"></a><font size=3>7. 应用函数</font></h2><p>这一部分开始，我们就开始实现，画点，画线，画矩形等一系列操作啦。</p>
<h3 id="7-1-基础函数"><a href="#7-1-基础函数" class="headerlink" title="7.1 基础函数"></a><font size=3>7.1 基础函数</font></h3><p>这里的函数都是后边画线等操作的基础。</p>
<h4 id="7-1-1-开窗"><a href="#7-1-1-开窗" class="headerlink" title="7.1.1 开窗"></a><font size=3>7.1.1 开窗</font></h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  在ILI9341显示器上开辟一个窗口</span></span><br><span class="line"><span class="comment">  * @note   </span></span><br><span class="line"><span class="comment">  * @param  usX 在特定扫描方向下窗口的起点X坐标</span></span><br><span class="line"><span class="comment">  * @param  usY 在特定扫描方向下窗口的起点Y坐标</span></span><br><span class="line"><span class="comment">  * @param  usWidth 窗口的宽度</span></span><br><span class="line"><span class="comment">  * @param  usHeight 窗口的高度</span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">ILI9341_OpenWindow</span><span class="params">(<span class="type">uint16_t</span> usX, <span class="type">uint16_t</span> usY, <span class="type">uint16_t</span> usWidth, <span class="type">uint16_t</span> usHeight)</span></span><br><span class="line">&#123;</span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x2A</span>);        <span class="comment">/* 设置X坐标 */</span></span><br><span class="line">    ILI9341_Write_Data(usX &gt;&gt; <span class="number">8</span>);   <span class="comment">/* 起始点的高8位 */</span></span><br><span class="line">    ILI9341_Write_Data(usX &amp; <span class="number">0xff</span>); <span class="comment">/* 起始点的低8位 */</span></span><br><span class="line">    ILI9341_Write_Data((usX + usWidth - <span class="number">1</span>) &gt;&gt; <span class="number">8</span>);  <span class="comment">/* 结束点的高8位 */</span></span><br><span class="line">    ILI9341_Write_Data((usX + usWidth - <span class="number">1</span>) &amp; <span class="number">0xff</span>);<span class="comment">/* 结束点的低8位 */</span></span><br><span class="line"></span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x2B</span>);        <span class="comment">/* 设置Y坐标 */</span></span><br><span class="line">    ILI9341_Write_Data(usY &gt;&gt; <span class="number">8</span>);</span><br><span class="line">    ILI9341_Write_Data(usY &amp; <span class="number">0xff</span>);</span><br><span class="line">    ILI9341_Write_Data((usY + usHeight - <span class="number">1</span>) &gt;&gt; <span class="number">8</span>);</span><br><span class="line">    ILI9341_Write_Data((usY + usHeight - <span class="number">1</span>) &amp; <span class="number">0xff</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="7-1-2-填充像素画图"><a href="#7-1-2-填充像素画图" class="headerlink" title="7.1.2 填充像素画图"></a><font size=3>7.1.2 填充像素画图</font></h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">   * @brief  在ILI9341显示器上以某一颜色填充像素点</span></span><br><span class="line"><span class="comment">   * @note   </span></span><br><span class="line"><span class="comment">   * @param  ulAmout_Point 要填充颜色的像素点的总数目</span></span><br><span class="line"><span class="comment">   * @param  usColor 颜色</span></span><br><span class="line"><span class="comment">   * @retval </span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line"><span class="type">static</span> __inline <span class="type">void</span> <span class="title function_">ILI9341_FillColor</span><span class="params">(<span class="type">uint32_t</span> ulAmout_Point, <span class="type">uint16_t</span> usColor)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">uint32_t</span> i = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* memory write */</span></span><br><span class="line">    ILI9341_Write_Cmd(<span class="number">0x2C</span>);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; ulAmout_Point; i++)</span><br><span class="line">    &#123;</span><br><span class="line">        ILI9341_Write_Data(usColor);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="7-1-3-清屏"><a href="#7-1-3-清屏" class="headerlink" title="7.1.3 清屏"></a><font size=3>7.1.3 清屏</font></h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  对ILI9341显示器的某一窗口以某种颜色进行清屏</span></span><br><span class="line"><span class="comment">  * @note   可使用LCD_SetBackColor、LCD_SetTextColor、LCD_SetColors函数设置颜色</span></span><br><span class="line"><span class="comment">  * @param  usX 在特定扫描方向下窗口的起点X坐标</span></span><br><span class="line"><span class="comment">  * @param  usY 在特定扫描方向下窗口的起点Y坐标</span></span><br><span class="line"><span class="comment">  * @param  usWidth 窗口的宽度</span></span><br><span class="line"><span class="comment">  * @param  usHeight 窗口的高度  </span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">ILI9341_Clear</span><span class="params">(<span class="type">uint16_t</span> usX, <span class="type">uint16_t</span> usY, <span class="type">uint16_t</span> usWidth, <span class="type">uint16_t</span> usHeight)</span></span><br><span class="line">&#123;</span><br><span class="line">    ILI9341_OpenWindow(usX, usY, usWidth, usHeight);</span><br><span class="line"></span><br><span class="line">    ILI9341_FillColor(usWidth * usHeight, lcd_param.BackColor);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="7-1-4-设置光标位置"><a href="#7-1-4-设置光标位置" class="headerlink" title="7.1.4 设置光标位置"></a><font size=3>7.1.4 设置光标位置</font></h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  设定ILI9341的光标坐标</span></span><br><span class="line"><span class="comment">  * @note   就是确定一个像素点的位置，方便后边画点</span></span><br><span class="line"><span class="comment">  * @param  usX 在特定扫描方向下光标的X坐标</span></span><br><span class="line"><span class="comment">  * @param  usY 在特定扫描方向下光标的Y坐标</span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">static</span> <span class="type">void</span> <span class="title function_">ILI9341_SetCursor</span><span class="params">(<span class="type">uint16_t</span> usX, <span class="type">uint16_t</span> usY)</span></span><br><span class="line">&#123;</span><br><span class="line">    ILI9341_OpenWindow(usX, usY, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>设置光标位置其实就是设置我们要显示的像素点的位置，将前边的开窗函数的窗口缩小到1就可以啦，注意这个函数仅仅是设置了位置，并不可以直接画一个点出来。</p>
<h4 id="7-1-5-画一个点"><a href="#7-1-5-画一个点" class="headerlink" title="7.1.5 画一个点"></a><font size=3>7.1.5 画一个点</font></h4><p>我们都知道，点组成线，线组成面，所以画点是最基础的啦：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  对ILI9341显示器的某一点以某种颜色进行填充</span></span><br><span class="line"><span class="comment">  * @note   画一个像素点，可使用LCD_SetBackColor、LCD_SetTextColor、LCD_SetColors函数设置颜色 </span></span><br><span class="line"><span class="comment">  * @param  usX 在特定扫描方向下该点的X坐标</span></span><br><span class="line"><span class="comment">  * @param  usY 在特定扫描方向下该点的Y坐标  </span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">ILI9341_SetPointPixel</span><span class="params">(<span class="type">uint16_t</span> usX, <span class="type">uint16_t</span> usY)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">if</span> ((usX &lt; lcd_param.LCD_X_LENGTH) &amp;&amp; (usY &lt; lcd_param.LCD_Y_LENGTH))</span><br><span class="line">    &#123;</span><br><span class="line">        ILI9341_SetCursor(usX, usY);<span class="comment">//设置像素点的位置</span></span><br><span class="line"></span><br><span class="line">        ILI9341_FillColor(<span class="number">1</span>, lcd_param.PonitColor);<span class="comment">//以指定颜色画点</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="7-2-业务函数"><a href="#7-2-业务函数" class="headerlink" title="7.2 业务函数"></a><font size=3>7.2 业务函数</font></h3><p>主要就是利用上边的基础函数，实现画线、画圆等一系列的操作。</p>
<h4 id="7-2-1-画线"><a href="#7-2-1-画线" class="headerlink" title="7.2.1 画线"></a><font size=3>7.2.1 画线</font></h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  在 ILI9341 显示器上使用 Bresenham 算法画线段</span></span><br><span class="line"><span class="comment">  * @note   可使用LCD_SetBackColor、LCD_SetTextColor、LCD_SetColors函数设置颜色</span></span><br><span class="line"><span class="comment">  * @param  usX1 在特定扫描方向下线段的一个端点X坐标</span></span><br><span class="line"><span class="comment">  * @param  usY1 在特定扫描方向下线段的一个端点Y坐标</span></span><br><span class="line"><span class="comment">  * @param  usX2 在特定扫描方向下线段的另一个端点X坐标</span></span><br><span class="line"><span class="comment">  * @param  usY2 在特定扫描方向下线段的另一个端点Y坐标 </span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">LCD_DrawLine</span><span class="params">(<span class="type">uint16_t</span> usX1, <span class="type">uint16_t</span> usY1, <span class="type">uint16_t</span> usX2, <span class="type">uint16_t</span> usY2)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">uint16_t</span> us;</span><br><span class="line">    <span class="type">uint16_t</span> usX_Current, usY_Current;</span><br><span class="line"></span><br><span class="line">    <span class="type">int32_t</span> lError_X = <span class="number">0</span>, lError_Y = <span class="number">0</span>, lDelta_X, lDelta_Y, lDistance;</span><br><span class="line">    <span class="type">int32_t</span> lIncrease_X, lIncrease_Y;</span><br><span class="line"></span><br><span class="line">    lDelta_X = usX2 - usX1; <span class="comment">// 计算坐标增量</span></span><br><span class="line">    lDelta_Y = usY2 - usY1;</span><br><span class="line"></span><br><span class="line">    usX_Current = usX1;</span><br><span class="line">    usY_Current = usY1;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (lDelta_X &gt; <span class="number">0</span>)</span><br><span class="line">        lIncrease_X = <span class="number">1</span>; <span class="comment">// 设置单步方向</span></span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span> (lDelta_X == <span class="number">0</span>)</span><br><span class="line">        lIncrease_X = <span class="number">0</span>; <span class="comment">// 垂直线</span></span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        lIncrease_X = <span class="number">-1</span>;</span><br><span class="line">        lDelta_X = -lDelta_X;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (lDelta_Y &gt; <span class="number">0</span>)</span><br><span class="line">        lIncrease_Y = <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span> (lDelta_Y == <span class="number">0</span>)</span><br><span class="line">        lIncrease_Y = <span class="number">0</span>; <span class="comment">// 水平线</span></span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        lIncrease_Y = <span class="number">-1</span>;</span><br><span class="line">        lDelta_Y = -lDelta_Y;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (lDelta_X &gt; lDelta_Y)</span><br><span class="line">        lDistance = lDelta_X; <span class="comment">// 选取基本增量坐标轴</span></span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">        lDistance = lDelta_Y;</span><br><span class="line">      </span><br><span class="line">    <span class="keyword">for</span> (us = <span class="number">0</span>; us &lt;= lDistance + <span class="number">1</span>; us++) <span class="comment">// 画线输出</span></span><br><span class="line">    &#123;</span><br><span class="line">        ILI9341_SetPointPixel(usX_Current, usY_Current); <span class="comment">// 画点</span></span><br><span class="line"></span><br><span class="line">        lError_X += lDelta_X;</span><br><span class="line">        lError_Y += lDelta_Y;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (lError_X &gt; lDistance)</span><br><span class="line">        &#123;</span><br><span class="line">          lError_X -= lDistance;</span><br><span class="line">          usX_Current += lIncrease_X;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (lError_Y &gt; lDistance)</span><br><span class="line">        &#123;</span><br><span class="line">          lError_Y -= lDistance;</span><br><span class="line">          usY_Current += lIncrease_Y;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="7-2-2-画矩形"><a href="#7-2-2-画矩形" class="headerlink" title="7.2.2 画矩形"></a><font size=3>7.2.2 画矩形</font></h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  在 ILI9341 显示器上画一个矩形</span></span><br><span class="line"><span class="comment">  * @note   可使用LCD_SetBackColor、LCD_SetTextColor、LCD_SetColors函数设置颜色</span></span><br><span class="line"><span class="comment">  * @param  usX_Start 在特定扫描方向下矩形的起始点X坐标</span></span><br><span class="line"><span class="comment">  * @param  usY_Start 在特定扫描方向下矩形的起始点Y坐标</span></span><br><span class="line"><span class="comment">  * @param  usWidth 矩形的宽度（单位：像素）</span></span><br><span class="line"><span class="comment">  * @param  usHeight 矩形的高度（单位：像素）</span></span><br><span class="line"><span class="comment">  * @param  ucFilled 选择是否填充该矩形,该参数为以下值之一：</span></span><br><span class="line"><span class="comment">  *             @arg 0,空心矩形</span></span><br><span class="line"><span class="comment">  *             @arg 1,实心矩形</span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">LCD_DrawRectangle</span><span class="params">(<span class="type">uint16_t</span> usX_Start, <span class="type">uint16_t</span> usY_Start, <span class="type">uint16_t</span> usWidth, <span class="type">uint16_t</span> usHeight, <span class="type">uint8_t</span> ucFilled)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">if</span> (ucFilled)</span><br><span class="line">    &#123;</span><br><span class="line">        ILI9341_OpenWindow(usX_Start, usY_Start, usWidth, usHeight);</span><br><span class="line">        ILI9341_FillColor(usWidth * usHeight, lcd_param.BackColor);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        LCD_DrawLine(usX_Start, usY_Start, usX_Start + usWidth - <span class="number">1</span>, usY_Start);</span><br><span class="line">        LCD_DrawLine(usX_Start, usY_Start + usHeight - <span class="number">1</span>, usX_Start + usWidth - <span class="number">1</span>, usY_Start + usHeight - <span class="number">1</span>);</span><br><span class="line">        LCD_DrawLine(usX_Start, usY_Start, usX_Start, usY_Start + usHeight - <span class="number">1</span>);</span><br><span class="line">        LCD_DrawLine(usX_Start + usWidth - <span class="number">1</span>, usY_Start, usX_Start + usWidth - <span class="number">1</span>, usY_Start + usHeight - <span class="number">1</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="7-2-3-画圆"><a href="#7-2-3-画圆" class="headerlink" title="7.2.3 画圆"></a><font size=3>7.2.3 画圆</font></h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  在 ILI9341 显示器上使用 Bresenham 算法画圆</span></span><br><span class="line"><span class="comment">  * @note   可使用LCD_SetBackColor、LCD_SetTextColor、LCD_SetColors函数设置颜色</span></span><br><span class="line"><span class="comment">  * @param  usX_Center ：在特定扫描方向下圆心的X坐标</span></span><br><span class="line"><span class="comment">  * @param  usY_Center ：在特定扫描方向下圆心的Y坐标</span></span><br><span class="line"><span class="comment">  * @param  usRadius：圆的半径（单位：像素）</span></span><br><span class="line"><span class="comment">  * @param  ucFilled ：选择是否填充该圆,该参数为以下值之一：</span></span><br><span class="line"><span class="comment">  *         @arg 0,空心圆</span></span><br><span class="line"><span class="comment">  *         @arg 1,实心圆 </span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">LCD_DrawCircle</span><span class="params">(<span class="type">uint16_t</span> usX_Center, <span class="type">uint16_t</span> usY_Center, <span class="type">uint16_t</span> usRadius, <span class="type">uint8_t</span> ucFilled)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">int16_t</span> sCurrentX, sCurrentY;</span><br><span class="line">    <span class="type">int16_t</span> sError;</span><br><span class="line"></span><br><span class="line">    sCurrentX = <span class="number">0</span>;</span><br><span class="line">    sCurrentY = usRadius;</span><br><span class="line"></span><br><span class="line">    sError = <span class="number">3</span> - (usRadius &lt;&lt; <span class="number">1</span>); <span class="comment">// 判断下个点位置的标志</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">while</span> (sCurrentX &lt;= sCurrentY)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="type">int16_t</span> sCountY;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (ucFilled)</span><br><span class="line">          <span class="keyword">for</span> (sCountY = sCurrentX; sCountY &lt;= sCurrentY; sCountY++)</span><br><span class="line">          &#123;</span><br><span class="line">            ILI9341_SetPointPixel(usX_Center + sCurrentX, usY_Center + sCountY); <span class="comment">// 1，研究对象</span></span><br><span class="line">            ILI9341_SetPointPixel(usX_Center - sCurrentX, usY_Center + sCountY); <span class="comment">// 2</span></span><br><span class="line">            ILI9341_SetPointPixel(usX_Center - sCountY, usY_Center + sCurrentX); <span class="comment">// 3</span></span><br><span class="line">            ILI9341_SetPointPixel(usX_Center - sCountY, usY_Center - sCurrentX); <span class="comment">// 4</span></span><br><span class="line">            ILI9341_SetPointPixel(usX_Center - sCurrentX, usY_Center - sCountY); <span class="comment">// 5</span></span><br><span class="line">            ILI9341_SetPointPixel(usX_Center + sCurrentX, usY_Center - sCountY); <span class="comment">// 6</span></span><br><span class="line">            ILI9341_SetPointPixel(usX_Center + sCountY, usY_Center - sCurrentX); <span class="comment">// 7</span></span><br><span class="line">            ILI9341_SetPointPixel(usX_Center + sCountY, usY_Center + sCurrentX); <span class="comment">// 0</span></span><br><span class="line">          &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">        &#123;</span><br><span class="line">          ILI9341_SetPointPixel(usX_Center + sCurrentX, usY_Center + sCurrentY); <span class="comment">// 1，研究对象</span></span><br><span class="line">          ILI9341_SetPointPixel(usX_Center - sCurrentX, usY_Center + sCurrentY); <span class="comment">// 2</span></span><br><span class="line">          ILI9341_SetPointPixel(usX_Center - sCurrentY, usY_Center + sCurrentX); <span class="comment">// 3</span></span><br><span class="line">          ILI9341_SetPointPixel(usX_Center - sCurrentY, usY_Center - sCurrentX); <span class="comment">// 4</span></span><br><span class="line">          ILI9341_SetPointPixel(usX_Center - sCurrentX, usY_Center - sCurrentY); <span class="comment">// 5</span></span><br><span class="line">          ILI9341_SetPointPixel(usX_Center + sCurrentX, usY_Center - sCurrentY); <span class="comment">// 6</span></span><br><span class="line">          ILI9341_SetPointPixel(usX_Center + sCurrentY, usY_Center - sCurrentX); <span class="comment">// 7</span></span><br><span class="line">          ILI9341_SetPointPixel(usX_Center + sCurrentY, usY_Center + sCurrentX); <span class="comment">// 0</span></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        sCurrentX++;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (sError &lt; <span class="number">0</span>)</span><br><span class="line">          sError += <span class="number">4</span> * sCurrentX + <span class="number">6</span>;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">        &#123;</span><br><span class="line">          sError += <span class="number">10</span> + <span class="number">4</span> * (sCurrentX - sCurrentY);</span><br><span class="line">          sCurrentY--;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="7-2-4-设置LCD背景颜色"><a href="#7-2-4-设置LCD背景颜色" class="headerlink" title="7.2.4 设置LCD背景颜色"></a><font size=3>7.2.4 设置LCD背景颜色</font></h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  设置LCD的背景颜色,RGB565</span></span><br><span class="line"><span class="comment">  * @note   </span></span><br><span class="line"><span class="comment">  * @param  Color 指定背景颜色 </span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">LCD_SetBackColor</span><span class="params">(<span class="type">uint16_t</span> Color)</span></span><br><span class="line">&#123;</span><br><span class="line">    lcd_param.BackColor = Color;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="7-2-5-设置LCD画笔颜色"><a href="#7-2-5-设置LCD画笔颜色" class="headerlink" title="7.2.5 设置LCD画笔颜色"></a><font size=3>7.2.5 设置LCD画笔颜色</font></h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  设置LCD的前景(字体)颜色,RGB565</span></span><br><span class="line"><span class="comment">  * @note   </span></span><br><span class="line"><span class="comment">  * @param  Color 指定前景(字体)颜色 </span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">LCD_SetTextColor</span><span class="params">(<span class="type">uint16_t</span> Color)</span></span><br><span class="line">&#123;</span><br><span class="line">    lcd_param.PonitColor = Color;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="7-3-测试函数"><a href="#7-3-测试函数" class="headerlink" title="7.3 测试函数"></a><font size=3>7.3 测试函数</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> <span class="title function_">LCD_Test</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">// 读取id</span></span><br><span class="line">    ILI9341_ID_Read();</span><br><span class="line"></span><br><span class="line">    ILI9341_Config();</span><br><span class="line">    ILI9341_GramScan(<span class="number">7</span>);</span><br><span class="line"></span><br><span class="line">    LCD_SetTextColor(RED);</span><br><span class="line">    </span><br><span class="line">    LCD_DrawLine(<span class="number">50</span>,<span class="number">50</span>,<span class="number">50</span>,<span class="number">200</span>);</span><br><span class="line">    LCD_DrawLine(<span class="number">50</span>,<span class="number">50</span>,<span class="number">150</span>,<span class="number">50</span>);</span><br><span class="line">    LCD_DrawLine(<span class="number">50</span>,<span class="number">130</span>,<span class="number">130</span>,<span class="number">130</span>);</span><br><span class="line"></span><br><span class="line">    LCD_Fill_Draw_Rectangle(<span class="number">0</span>, <span class="number">0</span>, <span class="number">30</span>, <span class="number">40</span>, BLUE);</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="8-完整参考代码"><a href="#8-完整参考代码" class="headerlink" title="8. 完整参考代码"></a><font size=3>8. 完整参考代码</font></h2><p>算了，500多行，后边还会再增加，可以看这个仓库：<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/stm32f103-prj">STM32F103-Prj: STM32学习使用 (gitee.com)</a></p>

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/91da98e9.html">LV16-26-LCD-04-LCD显示实现</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年06月04日 - 22:07</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/91da98e9.html" title="LV16-26-LCD-04-LCD显示实现">https://sumumm.github.io/post/91da98e9.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/LV16-STM32%E5%BC%80%E5%8F%91/" rel="tag"><i class="fa fa-tag"></i> LV16-STM32开发</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/6cd625e9.html" rel="prev" title="LV16-26-LCD-05-字符编码">
                  <i class="fa fa-angle-left"></i> LV16-26-LCD-05-字符编码
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/d605a74e.html" rel="next" title="LV16-26-LCD-03-ILI9341驱动LCD">
                  LV16-26-LCD-03-ILI9341驱动LCD <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
